﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using ThirdLife.UI.WinForms.Modules;

namespace ThirdLife.UI.WinForms.Controls
{
  public partial class TLCanvas3D : UserControl, IDockableUserControlView
  {
    private Canvas3D _module;

    public TLCanvas3D(Canvas3D module)
    {
      _module = module;
      InitializeComponent();
      ShowNonRenderingScreen();
    }

    public void SetupView()
    {
    }

    public void DestroyView()
    {

    }

    public int ControlId
    {
      get { return 1; }
    }

    public object Control
    {
      get { return this; }
    }

    public void ClearAllControls()
    {
      foreach (Control control in this.Controls )
      {
        this.Controls.Remove(control);
        control.Dispose();
      }
    }

    public IntPtr ShowReneringAreaAndGetDrawingAreaHandle()
    {
      ClearAllControls();
      UserControl renderingPanel = new UserControl();
      renderingPanel.Dock = DockStyle.Fill;
      renderingPanel.Disposed += new EventHandler(renderingPanel_Disposed);
      this.Controls.Add(renderingPanel);
      return renderingPanel.Handle;
    }

    void renderingPanel_Disposed(object sender, EventArgs e)
    {
      _module.TryToSafelyStopRenderer();
    }

    public void ShowNonRenderingScreen()
    {
      ClearAllControls();
      TLCake cake = new TLCake();
      cake.Dock = DockStyle.Fill;
      this.Controls.Add(cake);
    }
  }
}
